home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / layertes.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  6KB  |  171 lines

  1. /* layer test program v1.0 */
  2. /****************************************************************
  3. *                                                               *
  4. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  5. * No part of this program may be reproduced, transmitted,       *
  6. * transcribed, stored in retrieval system, or translated into   *
  7. * any language or computer language, in any form or by any      *
  8. * means, electronic, mechanical, magnetic, optical, chemical,   *
  9. * manual or otherwise, without the prior written permission of  *
  10. * Commodore Amiga Incorporated, 983 University Ave, #D          *
  11. * Los Gatos, CA 95030                                           *
  12. *                                                               *
  13. ****************************************************************/
  14.  
  15.  
  16.  
  17. #include <exec/types.h>
  18. #include <graphics/gfx.h>
  19. #include <hardware/dmabits.h>
  20. #include <hardware/custom.h>
  21. #include <graphics/gfxmacros.h>
  22. #include <graphics/rastport.h>
  23. #include <graphics/view.h>
  24. #include <exec/exec.h>
  25. /* ********************** added for layers support ************************ */
  26. #include <graphics/layers.h>
  27. #include <graphics/clip.h>
  28.  
  29.  
  30. #define DEPTH 2  
  31. #define WIDTH 320 
  32. #define HEIGHT 200 
  33. #define NOT_ENOUGH_MEMORY -1000
  34. #define FOREVER for(;;) 
  35.         /* construct a simple display */ 
  36.  
  37. #define FLAGS LAYERSMART
  38.  
  39. struct View v;
  40. struct ViewPort vp;
  41. struct ColorMap *cm;    /* pointer to colormap structure, dynamic alloc */
  42. struct RasInfo ri;
  43. struct BitMap b;
  44. /* made 3 separate rastports for layers testing ********************** */
  45. struct RastPort *rp[3];         /* rastport for each layer */
  46. /* dynamically created RastPorts from the calls to CreateUpfrontLayer */
  47.  
  48. short i,j,k,n;
  49. struct ColorMap *GetColorMap();
  50. struct GfxBase *GfxBase;
  51.  
  52. SHORT  boxoffsets[] = { 802, 2010, 3218 };
  53. USHORT colortable[] = { 0x000, 0xf00, 0x0f0, 0x00f };
  54.                         /* black, red, green, blue */
  55. UBYTE *displaymem;
  56. UWORD *colorpalette;
  57.  
  58. struct LayersBase *LayersBase;
  59. struct Layer_Info li;
  60. struct Layer *layer[3];
  61. extern struct Layer *CreateUpfrontLayer();
  62.  
  63. main()
  64. {
  65.         GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  66.         if (GfxBase == NULL) exit(1);
  67.  
  68.         LayersBase = (struct LayersBase *)OpenLibrary("layers.library",0); 
  69.         if(LayersBase == NULL) exit(2);
  70.  
  71.         InitLayers(&li);
  72.  
  73.                                 /* initialize view */
  74.         InitView(&v);
  75.                                 /* link view into viewport */
  76.         v.ViewPort = &vp;
  77.                                 /* init view port */
  78.         InitVPort(&vp);
  79.                                 /* now specify critical characteristics */
  80.         vp.DWidth = WIDTH;
  81.         vp.DHeight = HEIGHT;
  82.         vp.RasInfo = &ri;
  83.                                 /* init bit map (for rasinfo and rastport) */
  84.         InitBitMap(&b,DEPTH,WIDTH,HEIGHT);
  85.                                 /* (init RasInfo) */
  86.         ri.BitMap = &b;
  87.         ri.RxOffset = 0;        /* align upper left corners of display
  88.                                  * with upper left corner of drawing area */
  89.         ri.RyOffset = 0;
  90.         ri.Next = NULL;
  91.                                 /* (init color table) */
  92.         cm = GetColorMap(4);    /* 4 entries, since only 2 planes deep */
  93.         colorpalette = cm->ColorTable;
  94.         for(i=0; i<4; i++)
  95.                 *colorpalette++ = colortable[i];
  96.                                 /* copy my colors into this data structure */
  97.         vp.ColorMap = cm;       /* link it with the viewport */
  98.  
  99.                                  /* allocate space for bitmap */
  100.         for(i=0; i<DEPTH; i++)
  101.            {
  102.            b.Planes[i] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
  103.            if(b.Planes[i] == NULL) exit(NOT_ENOUGH_MEMORY);
  104.            }
  105.  
  106.         MakeVPort( &v, &vp );   /* construct copper instr (prelim) list */
  107.         MrgCop( &v );           /* merge prelim lists together into a real 
  108.                                  * copper list in the view structure. */
  109.  
  110.         for(i=0; i<2; i++)
  111.                 {
  112.                 displaymem = (UBYTE *)b.Planes[i];
  113.                 for(j=0; j<RASSIZE(WIDTH,HEIGHT); j++)
  114.                         *displaymem++ = 0;      
  115.                 /* zeros to all bytes of the display area */                                    }
  116.  
  117.         LoadView(&v);
  118.  
  119.         /* now fill some boxes so that user can see something */
  120.         /* always draw into both planes to assure true colors */
  121.  
  122.         layer[0] = CreateUpfrontLayer(&li,&b,20,20,100,80,FLAGS,NULL);
  123.                 /* layerinfo, common bitmap, x,y,x2,y2,
  124.                  * flags = 0 (simple refresh), null pointer to superbitmap */
  125.         
  126.         layer[1] = CreateUpfrontLayer(&li,&b,30,30,110,90,FLAGS,NULL);
  127.         layer[2] = CreateUpfrontLayer(&li,&b,40,40,120,100,FLAGS,NULL);
  128.  
  129.         if(layer[0]==NULL || layer[1]==NULL || layer[2]==NULL) exit(3);
  130.  
  131.         rp[0] = layer[0]->rp;
  132.         rp[1] = layer[1]->rp;
  133.         rp[2] = layer[2]->rp;
  134.  
  135.         SetAPen(rp[0],1);
  136.         SetDrMd(rp[0],JAM1);
  137.         RectFill(rp[0],0,0,160,100);
  138.  
  139.         SetAPen(rp[1],2);
  140.         SetDrMd(rp[1],JAM1);
  141.         RectFill(rp[1],0,0,160,100);
  142.  
  143.         SetAPen(rp[2],3);
  144.         SetDrMd(rp[2],JAM1);
  145.         RectFill(rp[2],0,0,160,100);
  146.  
  147.         FOREVER
  148.         moveit();
  149.         
  150.            ;            /* do nothing till user resets machine */ 
  151.  
  152.         FreeMemory();   /* discussion purposes only, user has no 
  153.                          * way here to get past "FOREVER" in this
  154.                          * simple program.  FreeMemory is discussed
  155.                          * in section below... Exiting Gracefully */
  156.  
  157. }       /* end of main() */
  158.  
  159.  
  160. FreeMemory()
  161. {               /* return user and system-allocated memory to sys manager */
  162.  
  163.         for(i=0; i<DEPTH; i++)                  /* free the drawing area */
  164.            FreeRaster(b.Planes[i],WIDTH,HEIGHT);
  165.         FreeColorMap(cm);                       /* free the color map */
  166.                 /* free dynamically created structures */
  167.         FreeVPortCopLists(&vp);                 
  168.         FreeCprList(&v.LOFCprList);
  169.         return;
  170. }       
  171.